<?php
echo $javascript->codeBlock("var swfupload_url='" . $html->url('/js/swfupload/SWFUpload.swf') . "';
                             var upload_url='" . $html->url('/files/upload') . "';
                             var file_info_url='" . $html->url('/files/info') . "';
                            ");
?>
<script type="text/javascript">
$().ready(function() {
	$("#businessForm").validate({
		errorLabelContainer: $("#businessForm div.error")
	});
});
</script>
<style type="text/css">
.cmxform fieldset p.error label { color: red; }
form.cmxform label.error {
	display: block;
	margin-left: 1em;
	width: auto;
}
</style>

<div id="search_result">
<form id="businessForm" name="businessForm" action="<?php echo $html->url('/business/register/'.$adsType); ?>" method="post" enctype="multipart/form-data">
    <div id="spacer"><?=$html->image('ldsyellow/spacer1x1.gif', array('height' => '40', 'alt' => ''))?></div>

    <div id="homebox">
        <div id="registerform">
            <div id="spacer"><?=$html->image('ldsyellow/spacer1x1.gif', array('height' => '10', 'alt' => ''))?></div>
            <div id="messagetitle" style="border: 1px solid #ccc; padding: 20px; background-color: #efefef;">
                <h1>Add<?=(isset($adsType)) ? " " . $adsType . " Listing" : ""?></h1>
            </div>
            <div id="spacer"><?=$html->image('ldsyellow/spacer1x1.gif', array('height' => '10', 'alt' => ''))?></div>
            <div id="message" class="maintext">
                <table width="95%" border="0" cellpadding="5" cellspacing="0" class="maintext">
                    <tr>
                        <td colspan=2>&nbsp;</td>
                    </tr>
                    <tr>
                    	<td colspan="2"><div class="error"></div></td>
                    </tr>
                    <tr>
                        <td width="30%" align="right"><font color="red"><b>*</b></font>&nbsp;Last Name</td>
                        <td width="%"><input type="text" name="data[register][lastname]" title="Please enter your lastname" class="{required:true}" style="width: 210px;"  /></td>
                    </tr>
                    <tr>
                        <td align="right"><font color="red"><b>*</b></font>&nbsp;First Name</td>
                        <td width="%"><input type="text" name="data[register][firstname]" title="Please enter your firstname" class="{required:true}" style="width: 210px;"  /></td>
                    </tr>
                    <tr>
                        <td align="right"><font color="red"><b>*</b></font>&nbsp;Email Address</td>
                        <td width="%"><input type="text" name="data[register][email_address]" title="Please enter your email address" class="{required:true,email:true}" style="width: 210px;"  /></td>
                    </tr>
                    <tr>
                        <td colspan=2><hr></td>
                    </tr>
                    <tr>
                        <td align="right"><font color="red"><b>*</b></font>&nbsp;Business Name</td>
                        <td><input type="text" name="data[register][business_name]" title="Please enter your business name" class="{required:true}" style="width: 210px;"  /></td>
                    </tr>
                    <tr>
                        <td colspan=2>&nbsp;</td>
                    </tr>
                    <tr>
                        <td align="right">Keywords to describe your company</td>
                        <td><input type="text" name="data[register][keywords]" style="width: 210px;"  /></td>
                    </tr>
                <?php
                 switch ($adsType) {
                    case "premium":
                 ?>
                    <tr>
                        <td align="right" valign="top">Description</td>
                        <td><textarea name="data[register][description]" cols="45" rows="10"></textarea></td>
                    </tr>
                    <tr valign="top">
                        <td valign="top">Category:</td>
                        <td>
                            <div style="padding: 5px;"><?php echo $form->select("category1", $categories, null, array("style" => "width: 210px;", 'title' => 'Please enter your business category', 'class' => '{required:true}'));?></div>
                            <div style="padding: 5px;"><?php echo $form->select("category2", $categories, null, array("style" => "width: 210px;", 'title' => 'Please enter your business category', 'class' => '{required:true}'));?></div>
                            <div style="padding: 5px;"><?php echo $form->select("category3", $categories, null, array("style" => "width: 210px;", 'title' => 'Please enter your business category', 'class' => '{required:true}'));?></div>
                            <div style="padding: 5px;"><?php echo $form->select("category4", $categories, null, array("style" => "width: 210px;", 'title' => 'Please enter your business category', 'class' => '{required:true}'));?></div>
                            <div style="padding: 5px;"><?php echo $form->select("category5", $categories, null, array("style" => "width: 210px;", 'title' => 'Please enter your business category', 'class' => '{required:true}'));?></div>
                            <div style="padding: 5px;"><?php echo $form->select("category6", $categories, null, array("style" => "width: 210px;", 'title' => 'Please enter your business category', 'class' => '{required:true}'));?></div>
                        </td>
                    </tr>
                    <tr>
                        <td align="right"><font color="red"><b>*</b></font>&nbsp;Street</td>
                        <td><input type="text" name="data[register][street]" title="Please enter your street" class="{required:true}" style="width: 210px;"  /></td>
                    </tr>
                    <tr>
                        <td align="right"><font color="red"><b>*</b></font>&nbsp;City</td>
                        <td><input type="text" name="data[register][city]" title="Please enter your city" class="{required:true}" style="width: 210px;"  /></td>
                    </tr>
                    <tr>
                        <td align="right"><font color="red"><b>*</b></font>&nbsp;State</td>
                        <td><?php echo $form->select("state", $states, null, array("style" => "width: 210px;", 'title' => 'Please enter state where you live', 'class' => '{required:true}')) ?></td>
                    </tr>
                    <tr>
                        <td align="right"><font color="red"><b>*</b></font>&nbsp;Zip Code</td>
                        <td><input type="text" name="data[register][zipcode]" title="Please enter your zip code" class="{required:true}" style="width: 100px;"  /></td>
                    </tr>
                    <tr>
                        <td align="right" valign="top"><font color="red"><b>*</b></font>&nbsp;Business Phone</td>
                        <td><input type="text" name="data[register][business_phone]" title="Please enter business phone" class="{required:true}" style="width: 210px;"  /></td>
                    </tr>
                    <tr>
                        <td align="right">Contact Person</td>
                        <td><input type="text" name="data[register][contact_person]" style="width: 210px;"  /></td>
                    </tr>
                    <tr>
                        <td align="right">Website</td>
                        <td><input type="text" name="data[register][contact_person]" value="http://" style="width: 210px;"  /></td>
                    </tr>
                    <tr>
                        <td align="right" valign="top">Graphic to Upload</td>
                        <td>
                            <input type="file" name="data[register][Image]"><p>JPG, GIF or BMP only.<br/>File size must be no larger than 1MB.</p>
                        </td>
                    </tr>
                <?php
                        break;

                    case "enhanced":
                 ?>
                    <tr>
                        <td align="right" valign="top">Description</td>
                        <td><textarea name="data[register][description]" cols="45" rows="10"></textarea></td>
                    </tr>
                    <tr valign="top">
                        <td valign="top">Category:</td>
                        <td>
                            <div style="padding: 5px;"><?php echo $form->select("category1", $categories, null, array("style" => "width: 210px;", 'title' => 'Please enter your business category', 'class' => '{required:true}'));?></div>
                            <div style="padding: 5px;"><?php echo $form->select("category2", $categories, null, array("style" => "width: 210px;", 'title' => 'Please enter your business category', 'class' => '{required:true}'));?></div>
                            <div style="padding: 5px;"><?php echo $form->select("category3", $categories, null, array("style" => "width: 210px;", 'title' => 'Please enter your business category', 'class' => '{required:true}'));?></div>
                        </td>
                    </tr>
                    <tr>
                        <td align="right"><font color="red"><b>*</b></font>&nbsp;Street</td>
                        <td><input type="text" name="data[register][street]" title="Please enter your street" class="{required:true}" style="width: 210px;"  /></td>
                    </tr>
                    <tr>
                        <td align="right"><font color="red"><b>*</b></font>&nbsp;City</td>
                        <td><input type="text" name="data[register][city]" title="Please enter your city" class="{required:true}" style="width: 210px;"  /></td>
                    </tr>
                    <tr>
                        <td align="right"><font color="red"><b>*</b></font>&nbsp;State</td>
                        <td><?php echo $form->select("state", $states, null, array("style" => "width: 210px;", 'title' => 'Please enter state where you live', 'class' => '{required:true}')) ?></td>
                    </tr>
                    <tr>
                        <td align="right"><font color="red"><b>*</b></font>&nbsp;Zip Code</td>
                        <td><input type="text" name="data[register][zipcode]" title="Please enter your zip code" class="{required:true}" style="width: 100px;"  /></td>
                    </tr>
                    <tr>
                        <td align="right" valign="top"><font color="red"><b>*</b></font>&nbsp;Business Phone</td>
                        <td>
                            <input type="text" name="data[register][business_phone]" title="Please enter business phone" class="{required:true}" style="width: 210px;"  />
                            <br>&nbsp;Please type business phone in correct format:&nbsp;<i>(999) 999-9999</i>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">Contact Person</td>
                        <td><input type="text" name="data[register][contact_person]" style="width: 210px;"  /></td>
                    </tr>
                    <tr>
                        <td align="right">Website</td>
                        <td><input type="text" name="data[register][website]" value="http://" style="width: 210px;"  /></td>
                    </tr>
                <?php
                        break;

                    case "basic":
                 ?>
                    <tr>
                        <td align="right" valign="top">Description</td>
                        <td><textarea name="data[register][description]" cols="45" rows="10"></textarea></td>
                    </tr>
                    <tr valign="top">
                        <td valign="top">Category:</td>
                        <td>
                            <div style="padding: 5px;"><?php echo $form->select("category1", $categories, null, array("style" => "width: 210px;", 'title' => 'Please enter your business category', 'class' => '{required:true}'));?></div>
                            <div style="padding: 5px;"><?php echo $form->select("category2", $categories, null, array("style" => "width: 210px;", 'title' => 'Please enter your business category', 'class' => '{required:true}'));?></div>
                            <div style="padding: 5px;"><?php echo $form->select("category3", $categories, null, array("style" => "width: 210px;", 'title' => 'Please enter your business category', 'class' => '{required:true}'));?></div>
                        </td>
                    </tr>
                    <tr>
                        <td align="right"><font color="red"><b>*</b></font>&nbsp;Street</td>
                        <td><input type="text" name="data[register][street]" title="Please enter your street" class="{required:true}" style="width: 210px;"  /></td>
                    </tr>
                    <tr>
                        <td align="right"><font color="red"><b>*</b></font>&nbsp;City</td>
                        <td><input type="text" name="data[register][city]" title="Please enter your city" class="{required:true}" style="width: 210px;"  /></td>
                    </tr>
                    <tr>
                        <td align="right"><font color="red"><b>*</b></font>&nbsp;State</td>
                        <td><?php echo $form->select("state", $states, null, array("style" => "width: 210px;", 'title' => 'Please enter state where you live', 'class' => '{required:true}')) ?></td>
                    </tr>
                    <tr>
                        <td align="right"><font color="red"><b>*</b></font>&nbsp;Zip Code</td>
                        <td><input type="text" name="data[register][zipcode]" title="Please enter your zip code" class="{required:true}" style="width: 100px;"  /></td>
                    </tr>
                    <tr>
                        <td align="right" valign="top"><font color="red"><b>*</b></font>&nbsp;Business Phone</td>
                        <td>
                            <input type="text" name="data[register][business_phone]" title="Please enter business phone" class="{required:true}" style="width: 210px;"  />
                            <br>&nbsp;Please type business phone in correct format:&nbsp;<i>(999) 999-9999</i>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">Contact Person</td>
                        <td><input type="text" name="data[register][contact_person]" style="width: 210px;"  /></td>
                    </tr>
                <?php
                        break;
                 }
                 ?>
                    <tr>
                        <td>&nbsp;</td>
                        <td>
                            <input type="image" src="/lds/themed/skin1/img/ldsyellow/btn-submit.gif" name="submit" height="26", width="80" border="0">
                        </td>
                    </tr>
    			    <tr>
    			        <td colspan=2>
    			            <font color="red">Asterisk <b>(*)</b> denotes required fields</font>
                        </td>
                    </tr>
                </table>
            </div>
            <div id="spacer"><?=$html->image('ldsyellow/spacer1x1.gif', array('height' => '10', 'alt' => ''))?></div>
        </div>
    </div>

    <div id="spacer"><?=$html->image('ldsyellow/spacer1x1.gif', array('height' => '40', 'alt' => ''))?></div>
    <input type="hidden" id="flag" name="flag">
    <input type="hidden" id="plan" name="plan" value="<?php echo $adsType; ?>">
    <input type="hidden" id="plan_id" name="plan_id" value="">
    <input type="hidden" id="uid" name="uid">
</form>
</div>
<script language="javascript">
function checkfields()
{
    var lastname = document.getElementById('lastname').value
    var firstname = document.getElementById('firstname').value
    var email = document.getElementById('email').value
    var bname = document.getElementById('businessname').value
    var street = document.getElementById('street').value
    var city = document.getElementById('city').value
    var state = document.getElementById('state').value
    var zipcode = document.getElementById('zipcode').value
    var contact_no = document.getElementById('contact_no').value

    var pattern_email = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/
    var pattern_phone_no = /(\(\d{3})\)\s\d{3}-\d{4}/
    var pattern_zipcode = /^\d{5}(-\d{4})?$/

    var x = 0

    if (!lastname || !firstname || !email || !bname || !street || !city || !state) {
        alert('All required information has not been filled out. Please be sure you have completed the form.')
    } else {
        if (email) {
            re = email.match(pattern_email)
            if (!re) {
                alert('Invalid email format')
                x++
            }
        }
        if (contact_no) {
            rc = contact_no.match(pattern_phone_no)
            if (!rc) {
                alert('Invalid phone number format')
                x++
            }
        }
        if (zipcode) {
            rz = zipcode.match(pattern_zipcode)
            if (!rz) {
                alert('Invalid zip code format')
                x++
            }
        }

        if (x == 0) {
            document.businessForm.submit();
        }
    }
}
function checkformat()
{
    var pattern = /(\+)?([-\._\(\) ]?[\d]{3,20}[-\._\(\) ]?){2,10}/
    result = document.getElementById('contact_no').value.match(pattern)
    if (!result) {
        alert('Contact number should be (999) 999-9999')
        document.getElementById('contact_no').focus()
    }
}
</script>
